package com.xiaowan.user.service.impl;

import com.xiaowan.model.common.dtos.ResponseResult;
import com.xiaowan.model.common.enums.AppHttpCodeEnum;
import com.xiaowan.model.user.EmergencyContactInfo;
import com.xiaowan.user.mapper.EmergencyContactInfoDao;
import com.xiaowan.user.service.EmergencyContactInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 实现功能：紧急联系人
 *
 * @author 作者[admin]
 * @version 1.0.00 2023-04-07 16:54
 */
@Service
public class EmergencyContactInfoServiceImpl implements EmergencyContactInfoService {
    @Autowired
    EmergencyContactInfoDao emergencyContactInfoDao;

    @Override
    public void addMessage(List<EmergencyContactInfo> list) {
        for (EmergencyContactInfo emergencyContactInfo : list) {
            emergencyContactInfo.setCreateTime(new Date());
            emergencyContactInfoDao.insert(emergencyContactInfo);
        }
    }

    @Override
    public List<EmergencyContactInfo> findEmergencyContactInfoById(Integer id) {
        return emergencyContactInfoDao.findEmergencyContactInfoById(id);
    }

    @Override
    public ResponseResult updateEmergencyContactInfo(EmergencyContactInfo emergencyContactInfo) {
        if (emergencyContactInfo == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        emergencyContactInfo.setUpdateTime(new Date());
        try {
            emergencyContactInfoDao.updateById(emergencyContactInfo);
            return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
        }
    }
}
